package components
{
	import UIFree.controls.uif_label;
	import UIFree.controls.uif_list;
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import flash.events.Event;
	import flash.geom.Rectangle;

	public class clt_list extends uif_list {
		private var _titleField: Object ;
		public function clt_list(parent:uif_component, ax:int, ay:int, awidth:int, aheight:int, 
								list: Array, a_selectFunc: Function, titleField: Object = 'name') {
			super(parent, ax, ay, awidth, aheight, 'list');
			
			addEvent(Event.CHANGE, function(e: Event): void {
				a_selectFunc((selectIndex > -1)?selectItem._data:null);
			});
			_titleField = titleField;
			attachList(list, null);
		}
		
		
		override public function attachList(list: Array, createFunc:  Function=null): uif_list {
			return super.attachList(list, (createFunc==null)?createItem:createFunc);
		}
		
		protected function createItem(area: uif_ecomponent, item: Object, index: int): uif_component {
			var inner: Rectangle = area.getInner();
			var ctrl: uif_label = new uif_label(area, inner.x, inner.y + index * 25, inner.width, 25, 'listItem');
			ctrl.text = (_titleField is Function)?_titleField(list[index]):list[index][_titleField]; 
			return ctrl;
		}
		
	}
}